'use strict';

angular.module('core')
    .controller('NavBarController', ['$scope', '$rootScope', '$state', '$location', 'User', 'Initialization',
        function($scope, $rootScope, $state, $location, User, Initialization) {
            $scope.data = {
                menuName: '',
                user: null
            };

            Initialization.initPromise.then(function() {
                init();
            });

            $scope.$on('profileChange', function () {
                init();
            });

            $scope.$on('subMenuChange', function (e, menu) {
                $scope.data.menuName = menu ? (menu.Name || '首页') : '首页';
            });

            $scope.signout = function() {
                User.signout();
                $state.go('UserLogin');
            };

            $scope.changePassword = function() {
                $state.go('index.ChangePassword');
            };

            $scope.goUpload = function() {
                $state.go('index.upload');
            };

            function init () {
                $scope.data.user = User.getProfile();
            }
        }
    ]);
